﻿using System;

namespace Lucene.Linq.VSTests.Helpers
{
    public static class RandomExtensions {

        public static string String(this Random r, int count) {
            return new RandomStringGenerator(r).NextString(count,true,false,false,false);
        }

        public static Guid Guid(this Random r) {
            return System.Guid.NewGuid();
        }

        public static string InvalidEmailAddress(this Random r) {
            var front = new RandomStringGenerator(r).NextString(r.Next(1, 10), true, true, true, true);
            var back = new RandomStringGenerator(r).NextString(r.Next(1, 10), true, true, true, true);
            return System.String.Format("{0}@{1}.com", front, back);
        }

        public static string EmailAddress(this Random r) {
            var front = new RandomStringGenerator(r).NextString(r.Next(1, 10), true, true, true, false);
            var back = new RandomStringGenerator(r).NextString(r.Next(1, 10), true, true, true, false);
            return System.String.Format("{0}@{1}.com", front, back);
        }

        public static string Name(this Random r) {
            return new RandomStringGenerator(r).NextString(r.Next(1, 20), true, true, false, false);
        }

        public static string FullName(this Random r) {
            var front = new RandomStringGenerator(r).NextString(r.Next(1, 10), true, true, false, false);
            var back = new RandomStringGenerator(r).NextString(r.Next(1, 10), true, true, false, false);
            return System.String.Format("{0} {1}", front, back);
        }

        public static Uri HttpUrl(this Random r) {
            var hostName = new RandomStringGenerator(r).NextString(r.Next(1, 10), true, true, true, false);
            var path = new RandomStringGenerator(r).NextString(r.Next(10), true, true, false, false);
            return new Uri(System.String.Format("http://www.{0}.com.au/{1}", hostName, path));
        }

        public static T Enum<T>(this Random r) {
            T[] values = (T[])System.Enum.GetValues(typeof(T));
            return values[r.Next(0, values.Length)];
        }

    }
}